<?php
require_once 'init-ise.php';
session_start();
$conversation = ReservationConversation::getCurrent();
?>
<html>
<head>
	<title>Reservation Test</title>
</head>
<body>
	<h2>Action:</h2>
	<p>
	<?php 
	$action = "undefined";
	if ($_SERVER['REQUEST_METHOD'] == 'GET' && isset($_GET['action'])) {
		$action = $_GET['action'];
		if ($action === 'category') {
			$cat = CategoryQuery::create()->findPk("compact");
			print "Setting category :".$cat;
			$conversation->category($cat);
		} else if ($action === 'stations') {
			$station = StationQuery::create()->findOneByStationid(2);
			print "\nSetting station :".$station;
			$conversation->stations($station);
		} else if ($action === 'customer') {
			$customer = CustomerQuery::create()->findPk(2);
			print "\nSetting customer :".$customer;
			$conversation->owner($customer);
		} else if ($action === 'dates') {
			$now = new DateTime();
			$then = new DateTime();
			$then->add(new DateInterval("P2D"));	// 2 days later (.
			print "\nSetting start :".$now->format("Y-m-d")." end :".$then->format("Y-m-d");
			$conversation->range($now, $then);
		} else if ($action === 'finish') {
			print "Finishing";
			$conversation->finish();
		} else if ($action === 'reset') {
			print "Abort";
			$conversation->terminate();
			$conversation = ReservationConversation::getCurrent();
		}
	}
	?>
	</p>
	<h2>Session value is:</h2>
	<p>
	<?php 
	print $_SESSION["CONVERSATION_RESERVATION"];
	?>
	</p>
	<h2>Current reservation is:</h2>
	<p>
	<?php
	print $conversation;
	?>
	</p>
	<form action="" method="get">
		<input type="hidden" name="action" value="category" />
		<input type="submit" value="Set Category" />
	</form>
	<form action="" method="get">
		<input type="hidden" name="action" value="stations" />
		<input type="submit" value="Set Pickup & Dropoff" />
	</form>
	<form action="" method="get">
		<input type="hidden" name="action" value="customer" />
		<input type="submit" value="Set Customer" />
	</form>
	<form action="" method="get">
		<input type="hidden" name="action" value="dates" />
		<input type="submit" value="Set Start & End Date" />
	</form>
	<form action="" method="get">
		<input type="hidden" name="action" value="finish" />
		<input type="submit" value="Finish" />
	</form>
	<form action="" method="get">
		<input type="hidden" name="action" value="reset" />
		<input type="submit" value="Reset" />
	</form>
</body>
</html>